package com.zhengx.fragmentutildemo.pager.item;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.zhengx.fragmentutil.BaseQuickFragment;
import com.zhengx.fragmentutildemo.FragmentOne;
import com.zhengx.fragmentutildemo.R;

/**
 * name：com.zhengx.fragmentutildemo.pager.item
 * class: describe
 * author: zhengx
 * create_time: 19-9-23
 */
public class FragmentItem extends BaseQuickFragment {

    public static FragmentItem create(int no) {
        FragmentItem fragmentItem = new FragmentItem();
        Bundle args = new Bundle();
        args.putInt("NO", no);
        fragmentItem.setArguments(args);
        return fragmentItem;
    }

    private TextView tvContent;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.layout_fragment_item, container, false);
        tvContent = view.findViewById(R.id.tv_content);
        tvContent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getActivity(), ItemDetailActivity.class));
            }
        });
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        if (getArguments() != null) {
            int NO = getArguments().getInt("NO", 1);
            tvContent.setText("FragmentItem编号:" + NO);
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        Log.e(FragmentOne.class.getSimpleName(), "fragment item " + getArguments().getInt("NO", 1) + "in pager2 ==> 可见");
    }

    @Override
    public void onPause() {
        super.onPause();
        Log.e(FragmentOne.class.getSimpleName(), "fragment item " + getArguments().getInt("NO", 1) + "in pager2 ==> 不可见");
    }
}
